    //
//  RightPanel.m
//  ModuleTesting
//
//  Created by duc nguyen van on 8/30/11.
//  Copyright 2011 STU. All rights reserved.
//

#import "RightPanel.h"
#define WidthEntityImage 170
#define HeightEntityImage 170

@implementation RightPanel
@synthesize delegate,isOpen,scrollEntity;
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/
#pragma mark -
#pragma mark check event

-(void)tapRightCrollEntity:(UITapGestureRecognizer*)tap{
	CGPoint point = [tap locationInView:scrollEntity];
	
	int page = floor(point.y / scrollEntity.contentSize.width) + 1;
	[delegate chooseEntityWithPage:page];
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];		
	
	NSArray *arrImages = [[NSArray alloc] initWithObjects:@"actor1.png",@"actor2.png",@"activity.png",@"classdiagram1.png",@"classdiagram2.png",
					@"cloud.png",@"database.png",@"note.png",@"packagename.png",nil];
	
	int i = 0;
	for (NSString *image in arrImages) {
		UIImage *ima = [UIImage imageNamed:image];
		UIImageView *imageView = [[UIImageView alloc] initWithImage:ima];
		
		imageView.contentMode = UIViewContentModeScaleToFill;
		imageView.clipsToBounds = YES;
		
		imageView.frame = CGRectMake( 0, WidthEntityImage * i++, WidthEntityImage, HeightEntityImage);
		[scrollEntity addSubview:imageView];
		[imageView release];
	}
	scrollEntity.contentSize = CGSizeMake(WidthEntityImage, HeightEntityImage * i);
	
	UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRightCrollEntity:)];
	[scrollEntity addGestureRecognizer:tap];
	[tap release];
}


-(IBAction)tapButtonMove{
	[UIView beginAnimations:nil context:NULL];
	if (isOpen) {
		self.view.frame = CGRectMake(self.view.frame.origin.x + self.view.frame.size.width - 12,
									 self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
		isOpen = NO;
	}
	else {
		self.view.frame = CGRectMake(self.view.frame.origin.x - self.view.frame.size.width + 12,
									 self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
		isOpen = YES;
	}
	[UIView setAnimationCurve:1000];
	[UIView commitAnimations];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return YES;
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}


- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
